package com.yzqp.generator.util.generator.java;

import com.yzqp.generator.prop.java.GeneratorBaseProp;
import com.yzqp.generator.prop.java.GeneratorControllerProp;
import com.yzqp.generator.util.generator.filter.column.TableColumnFilter;
import com.yzqp.generator.util.generator.filter.column.add.AddJavaTypeColumnFilter;
import com.yzqp.generator.util.generator.filter.column.delete.DeleteJavaBaseBeanColumnFilter;
import com.yzqp.generator.util.generator.filter.map.GeneratorMapFilter;
import com.yzqp.generator.util.generator.filter.map.add.AddBaseTempleParamMapFilter;
import com.yzqp.generator.util.generator.filter.map.add.AddJavaClassNameAndLocationPackageMapFilter;
import com.yzqp.generator.util.generator.filter.map.add.AddJavaPackageListMapFilter;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * 生成controller 的工具类
 *
 * @author hejiacheng
 * @date 2022/3/7
 */
@Component
@Data
public class GeneratorJavaController extends BaseGenerator {


    private GeneratorControllerProp prop;

    @Autowired
    public GeneratorJavaController(GeneratorControllerProp prop, GeneratorBaseProp generatorBaseProp) {
        super();
        this.prop = prop;
        // 1.设置列过滤器
        List<TableColumnFilter> tableColumnFilters = new ArrayList<>();
        // 过滤 删除 BaseBean 中的属性
        tableColumnFilters.add(new DeleteJavaBaseBeanColumnFilter());
        // 过滤 新增 javaType javaFieldName
        tableColumnFilters.add(new AddJavaTypeColumnFilter());
        // 设置过滤数据
        super.setTableColumnFilters(tableColumnFilters);


        // 2.设置生成器map过滤器
        List<GeneratorMapFilter> mapFilters = new ArrayList<>();
        // 过滤 新增 基础模板过滤器
        mapFilters.add(new AddBaseTempleParamMapFilter());
        // 过滤 新增 java的 类名 和 所在的包
        mapFilters.add(new AddJavaClassNameAndLocationPackageMapFilter(prop.getLastPackage(), prop.getPostfix(), generatorBaseProp));
        // 过滤 新增 java需要引入的包
        mapFilters.add(new AddJavaPackageListMapFilter(prop.getPostfix(), generatorBaseProp));
        // 设置map过滤器
        super.setGeneratorMapFilters(mapFilters);


    }


    @Override
    public String getTemplePath() {
        return prop.getTemplePath();
    }

    @Override
    protected String getGeneratorFilePath() {
        return prop.getGeneratorFilePath();
    }
}
